//index.js
//获取应用实例
const app = getApp()
import API from '../../api/API.js'

Page({
  data: {
    motto: 'Hello World',
    activeList:['活动','沙发','即刻','日常'],
    tag:0,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    autoplay: true,
    interval: 3000,
    duration: 1000,
    loadingMoreHidden: true,
    page: 1,
    pageSize: 10,
    banners: [{
      id: 1
    }, {
      id: 2
    }],
    hotActivitys: []
  },
  // 选择tab标题
  selectActive: function (e) {
    console.log(e);
    this.setData({
      tag: e.target.dataset.tag
    })
  },

  swiperchange: function(e) {
    //console.log(e.detail.current)
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  onReachBottom: function() {
    console.log('bottom')
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  goDetail: function (e) {
    console.log(e.currentTarget.dataset.id)
    var actId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/activity-detail/activity-detail?actId=' + actId
    })
  },


  onLoad: function() {
    let that = this;
    var params = {
      page: 1,
      pageSize: 10,
      actType: 1
    }
    console.log('onLoad')
    API.getActivitys(params, function (data) {
      that.setData({
        hotActivitys: data.list
      })
    })


  },

  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {
    var params = {
      page: 1,
      pageSize: 10,
      actType: 1
    }
    API.getActivitys(params, function (data) {
      that.setData({
        hotActivitys: data.list
      })
    })
  },


  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})